﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Viet_Calculator
{
	/// <summary>
	/// Summary description for frmCF.
	/// </summary>
	public class frmCF : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Button btnC2F;
		private System.Windows.Forms.Button btnF2C;
		private System.Windows.Forms.TextBox txtDoC1;
		private System.Windows.Forms.TextBox txtDoF2;
		private System.Windows.Forms.TextBox txtDoF1;
		private System.Windows.Forms.TextBox txtDoC2;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmCF()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmCF));
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.txtDoC1 = new System.Windows.Forms.TextBox();
			this.txtDoF2 = new System.Windows.Forms.TextBox();
			this.txtDoF1 = new System.Windows.Forms.TextBox();
			this.txtDoC2 = new System.Windows.Forms.TextBox();
			this.btnC2F = new System.Windows.Forms.Button();
			this.btnF2C = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Location = new System.Drawing.Point(16, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(35, 18);
			this.label1.TabIndex = 0;
			this.label1.Text = "Độ C";
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label2.Location = new System.Drawing.Point(16, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(34, 18);
			this.label2.TabIndex = 1;
			this.label2.Text = "Độ F";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label3.Location = new System.Drawing.Point(168, 16);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(34, 18);
			this.label3.TabIndex = 2;
			this.label3.Text = "Độ F";
			// 
			// label4
			// 
			this.label4.AutoSize = true;
			this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label4.Location = new System.Drawing.Point(168, 48);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(35, 18);
			this.label4.TabIndex = 3;
			this.label4.Text = "Độ C";
			// 
			// txtDoC1
			// 
			this.txtDoC1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtDoC1.Location = new System.Drawing.Point(64, 16);
			this.txtDoC1.Name = "txtDoC1";
			this.txtDoC1.Size = new System.Drawing.Size(88, 22);
			this.txtDoC1.TabIndex = 4;
			this.txtDoC1.Text = "";
			// 
			// txtDoF2
			// 
			this.txtDoF2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtDoF2.Location = new System.Drawing.Point(64, 48);
			this.txtDoF2.Name = "txtDoF2";
			this.txtDoF2.Size = new System.Drawing.Size(88, 22);
			this.txtDoF2.TabIndex = 5;
			this.txtDoF2.Text = "";
			// 
			// txtDoF1
			// 
			this.txtDoF1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtDoF1.Location = new System.Drawing.Point(216, 16);
			this.txtDoF1.Name = "txtDoF1";
			this.txtDoF1.ReadOnly = true;
			this.txtDoF1.Size = new System.Drawing.Size(88, 22);
			this.txtDoF1.TabIndex = 6;
			this.txtDoF1.Text = "";
			// 
			// txtDoC2
			// 
			this.txtDoC2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.txtDoC2.Location = new System.Drawing.Point(216, 48);
			this.txtDoC2.Name = "txtDoC2";
			this.txtDoC2.ReadOnly = true;
			this.txtDoC2.Size = new System.Drawing.Size(88, 22);
			this.txtDoC2.TabIndex = 7;
			this.txtDoC2.Text = "";
			// 
			// btnC2F
			// 
			this.btnC2F.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnC2F.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnC2F.Location = new System.Drawing.Point(320, 16);
			this.btnC2F.Name = "btnC2F";
			this.btnC2F.Size = new System.Drawing.Size(136, 24);
			this.btnC2F.TabIndex = 8;
			this.btnC2F.Text = "Độ C ---> Độ F";
			this.btnC2F.Click += new System.EventHandler(this.btnC2F_Click);
			// 
			// btnF2C
			// 
			this.btnF2C.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnF2C.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnF2C.Location = new System.Drawing.Point(320, 48);
			this.btnF2C.Name = "btnF2C";
			this.btnF2C.Size = new System.Drawing.Size(136, 24);
			this.btnF2C.TabIndex = 9;
			this.btnF2C.Text = "Độ F ---> Độ C";
			this.btnF2C.Click += new System.EventHandler(this.btnF2C_Click);
			// 
			// frmCF
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(466, 87);
			this.Controls.Add(this.btnF2C);
			this.Controls.Add(this.btnC2F);
			this.Controls.Add(this.txtDoC2);
			this.Controls.Add(this.txtDoF1);
			this.Controls.Add(this.txtDoF2);
			this.Controls.Add(this.txtDoC1);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.Name = "frmCF";
			this.Text = "Chuyen doi do C sang do F va nguoc lai";
			this.ResumeLayout(false);

		}
		#endregion


		double dblDoC, dblDoF;

		// Chuyển đổi từ độ C sang độ F
		private void btnC2F_Click(object sender, System.EventArgs e)
		{
			try
			{
				if (txtDoC1.Text == "")
				{
					MessageBox.Show("Bạn hãy điền vào ô trống một giá trị!");
				}
				else
				{
					dblDoC = Convert.ToDouble(txtDoC1.Text);
					dblDoF = dblDoC*1.8+32;
					txtDoF1.Text = dblDoF.ToString();
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show("Đã có lỗi xảy ra trong quá trình chuyển đổi! Bạn hãy kiểm tra xem mình đã thao tác đúng chưa nhé!", ex.Source);
			}
		}

		// Chuyển đổi từ độ F sang độ C
		private void btnF2C_Click(object sender, System.EventArgs e)
		{
			try
			{
				if (txtDoF2.Text == "")
				{
					MessageBox.Show("Bạn hãy điền vào ô trống một giá trị!");
				}
				else
				{
					dblDoF = Convert.ToDouble(txtDoF2.Text);
					dblDoC = (dblDoF-32)/1.8;
					txtDoC2.Text = dblDoC.ToString();
				}
			}
			catch(Exception ex)
			{
				MessageBox.Show("Đã có lỗi xảy ra trong quá trình chuyển đổi! Bạn hãy kiểm tra xem mình đã thao tác đúng chưa nhé!", ex.Source);
			}
		}
	}
}
